home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
03
/
8
/
DISK0381.ZIP
/
BRENTBAS.UM
< prev
next >
Wrap
Text File
|
1985-02-09
|
23KB
|
1,387 lines
The Brentbas User's Manual
Licence: You may use this document and the Brentbas program free
for a period of sixty days. If you wish to use the program after
that time, you must send a $10 registration fee to
Brent D. Weaver
1950 Oak View Drive
Oakland, California 94602
Registered users may make copies of this document and the
Brentbas program provided that any additional users of this
document and the Brentbas program abide by this licence agree-
ment.
Brentbas is a trademark of Brent D. Weaver.
Microsoft is a trademark of Microsoft Corporation.
Copyright 1985 By Brent D. Weaver Page 1
The Brentbas User's Manual
1. Introduction
Brentbas is an translator from a structured BASIC to Microsoft
BASIC. The syntax of the structured BASIC is a superset of the
RatBas language developed by W.F. Sharpe and myself at Wells
Fargo Investment Advisors. This text should be used as an update
of the RATBAS.UM user's manual.
This new translator has the following new features:
1. It is capable of translating over 1500 lines per minute
without using a RAM disk.
2. DOS 2.0 Path Names can be used for "include" files.
3. Input, Output, Map files, and Options can be read from the
command line.
4. Cross-reference of procedure calls.
5. Nesting of "include" files.
6. DO...BREAK...ENDDO and DO...CONTINUE...ENDDO structures.
7. GOTO(label) and RESUME(label) options for error processing.
8. Compressed Code option (/X) and commented code option (/V).
9. Provision for multiple-line statement and commenting.
Copyright 1985 By Brent D. Weaver Page 2
The Brentbas User's Manual
2. Running the Translator
The syntax of running the translator is patterned on the IBM
Basic Compiler.
Brentbas [filespec][options],[filespec],[filespec]
The file specification may contain a disk drive, a directory
path, a "root" name, and an extension. To make clear how default
path names are handled, the examples will be displayed assuming
the following command has been executed in the autoexec.bat file:
c> prompt $p$n
The three file specifications are for the input file, the output
file and the map file respectively. For example:
(1) c\run> brentbas c:\source\myprog.rat,c:\run\myprog.bas,
c:\run\myprog.xmp
If the output file is omitted, the root name of the input file is
used along with the current directory and the ".BAS" extension.
For example:
(2) c:\run> brentbas c:\source\myprog,,;
achieves the same result as example (1). If you do not want a
listing file, you simple remove the commas:
(3) c:run> brentbas c:\source\myprog;
If you enter no arguments, the program will prompt you for the
information.
Options
The following options are available:
/b do not pause for errors.
/n remove unnecessary line numbers to improve optimization
for the BASIC compiler.
/v (verbose). Adds commenting of ifend's, calls, and
procedures.
/x Removes all comments, extra spaces, and non-executable
lines. This option may be required if you are using the
/X option of the Basic compiler.
/+ Do not process + at end of lines as concatenation
indicators.
Copyright 1985 By Brent D. Weaver Page 3
The Brentbas User's Manual
/i:path default path for include files
One should not use /v and /x at the same time. For the /i: com-
mand, be sure to indicate both the disk drive and the directory.
Further examples:
(4) c:basic> brentbas myprog/n;
(5) c:basic> brentbas myprog,myprog.tst/x/i:a:\,map
Copyright 1985 By Brent D. Weaver Page 4
The Brentbas User's Manual
3. "Do" Structure
The DO structure is provided to add the "break" and "continue"
control structures found in the C language. There are two forms
of the DO structure: the FOR and the WHILE. The first one trans-
lates to the BASIC FOR..NEXT construct. Its syntax is:
FOR variable=expression to expression DO]
statement
statement
ENDDO
For example:
' Skip count number of lines
FOR i=1 to count DO]
print
ENDDO]
translates to
100 FOR I=1 TO COUNT
105 PRINT
110 NEXT
The second translates to the BASIC WHILE..WEND structure. For
example:
' Display File
WHILE not eof(1) DO]
line input #1, theline$
print line$
ENDDO]
translates to:
100 WHILE NOT EOF(1)
105 LINE INPUT #1, THELINE$
110 PRINT LINE$
115 WEND
Now this may seem like a useless feature. However, if you use the
DO..ENDDO structure, the Brentbas translator can check for im-
proper nesting of FOR..NEXT and WHILE..WEND loops with IF..IFEND,
CASE..CEND, and PROCEDURE..PEND structures. Additionally the
"break" and "continue" structures are enabled.
The BREAK structure is used to prematurely exit from a FOR..NEXT
or WHILE..WEND loop. For example:
Copyright 1985 By Brent D. Weaver Page 5
The Brentbas User's Manual
' Skip count number of lines unless at bottom of screen.
PROCEDURE Skip(count.skip)]
FOR i=1 to count.skip DO]
if csrlin>=24 BREAK]
print
ENDDO]
PEND]
translates to:
100 FOR I=1 TO COUNT.SKIP
105 IF CSRLIN>=24 GOTO 120
110 PRINT
115 NEXT
120 RETURN
The. CONTINUE statement skips the remainder of the FOR..NEXT loop
or WHILE..WEND loop and goes to the next iteration. For example:
' Display File except comment lines
WHILE not eof(1) DO]
line input #1, theline$
if left$(theline$,1)="." CONTINUE]
print line$
ENDDO]
translates to:
100 WHILE NOT EOF(1)
105 LINE INPUT #1, THELINE$
110 IF LEFT$(THELINE$,1)="." GOTO 120
115 PRINT LINE$
120 WEND
Copyright 1985 By Brent D. Weaver Page 6
The Brentbas User's Manual
4. Initialization Blocks
When using INCLUDE files, you may need to dimension and/or ini-
tialize certain variables used in the procedures in the proce-
dures in the include file. All blocks of the following form are
executed at the start of the program.
INITIAL]
statement
statement
INITEND]
You may have multiple INITIAL..INITEND blocks.
Copyright 1985 By Brent D. Weaver Page 7
The Brentbas User's Manual
5. GOTO feature
To handle multiple error trapping blocks, the GOTO and RESUME
feature is provided.
LABEL OPENERR]
on error goto 0 'disable this error block
PRINT infile$;" cannot be opened. Error #";err
Askyn("Do you wish to continue",ok)]
if ok RESUME(ASKNAME)]
RESUME(ENDOPEN)]
'
PROCEDURE OPENFILE]
LABEL ASKNAME]
on error goto(OPENERR)]
INPUT "Enter Name of File";infile$
OPEN infile$ for input as #1
LABEL ENDOPEN]
PEND]
There are also rare cases where the GOTO..LABEL contruct is
preferred to other control structures. This should be used spar-
ingly, if at all.
Copyright 1985 By Brent D. Weaver Page 8
The Brentbas User's Manual
6. Additional Features of Include Files
The INCLUDE instruction can now used path names. If path names
are used, you must put the name in quote marks.
INCLUDE "C:\FILETOOLS\OPEN"]
The default path can be changed by use of the /I: option. If a
drive letter is provided without a path name, the default path
name will be used even if the default path is for a different
drive.
Include Files can now be nested to a level of 3.
Copyright 1985 By Brent D. Weaver Page 9
The Brentbas User's Manual
7. I/O Routines and Memory
If DOS 2.0 is used with 196 KB or more of internal memory, spe-
cial file buffering is used to greatly increase the speed of the
translator. A RAM disk is not necessary. If you are using a RAM
disk, you should use it to hold the "include" files and possibly
the main input file. There is no need to put the output file on
the RAM disk unless you plan to immediately compile the BASIC
code.
If DOS 1.1 is used or if there is less than 196 KB memory, stand-
ard i/o will be used without extra buffering.
The buffering methods make it almost impossible to run out of
memory in the translation stage unless a program is so large that
BASIC would not be able to compile/interpret it anyway.
Copyright 1985 By Brent D. Weaver Page 10
The Brentbas User's Manual
8. Comment Statements
The "/*" symbol is used to indicate comments to the Translator.
This is useful in commenting out code. The apostrophe is used for
comments that you wish to include in the BASIC code.
Copyright 1985 By Brent D. Weaver Page 11
The Brentbas User's Manual
9. Line concatenation
You may concatenate two or more lines in your source code into
one line of BASIC. The '+' symbol at the end of a line is used to
indicate that the next line is to be considered a continuation.
For example:
IF (a>b) and + /* Lower Bound of A
(a<c) + /* Upper Bound of A
THEN]
print "Within Range"
ELSE]
print "Out of Range"
IFEND]
' end of check
translates to:
100 IF (A>B) AND (A<C) THEN ELSE GOTO 115
105 PRINT "Within Range"
110 GOTO 120
115 PRINT "Out of Range"
120 ' end of check
The resulting BASIC line cannot exceed 255 characters.
Copyright 1985 By Brent D. Weaver Page 12
The Brentbas User's Manual
10. Procedure Cross Reference
In addition to the line numbers of each procedure, the translator
also produces the first and last lines where the procedure is
called. If these numbers are zero, you may safely remove the
code. The Cross reference is now placed in a separate "XMP"
output file.
Copyright 1985 By Brent D. Weaver Page 13
The Brentbas User's Manual
11. Code compression option.
Code compression may be desired if the resulting code is to be
interpreted or if the /X option is used with the compiler. The /X
option of the compiler places line numbers in the EXE file. For
large programs, this can lead to a "TOO COMPLEX" error message.
The /X option of the Brentbas translator removes all comments,
extra spaces, and lines that do not contain code. The /X option
does not alter variable names.
Copyright 1985 By Brent D. Weaver Page 14
The Brentbas User's Manual
12. Multiple Right Hand Side Variables in selection statements
The RATBAS.UM manual neglected to state the option that multiple
right hand side variables could be placed in selection statements
if separated by commas. For example,
CASE let$ OF]
"y","Y" :]
code=TRUE;
"n","N" :]
code=FALSE;
OTHERWISE]
print "Please answer Y or N"
CEND]
Copyright 1985 By Brent D. Weaver Page 15
The Brentbas User's Manual
13. Review of the Language
The following is a definition of the Brentbas language. Where
more than one definition is allowed, each definition is given a
number if parenthesis. Where a line or part of a line is op-
tional, it is enclosed in braces ("{}"). The closing square
bracket ("]") is a special symbol in the language.
brentbas program:
multiple_blocks
program_line
multiple_blocks
multiple_blocks:
init_or_proc_block
{multiple_blocks}
init_of_proc_block:
(1) init_block
initial_line
brentbas_block
initend_line
(2) procedure_block
procedure_line]
brentbas_block
pend_line]
Copyright 1985 By Brent D. Weaver Page 16
The Brentbas User's Manual
brentbas_block:
(1)
{brentbas_block}
normal_line
{brentbas_block}
(2) if_block
(a)
then_line
brentbas_block
ifend_line
(b)
then_line
brentbas_block
else_block
brentbas_block
ifend_line
(3) case_block
(a)
case_line
selection_block
cend_line
(b)
case_line
selection_block
otherwise_line
brentbas_block
cend_line
(4) do_block
(a)
do_line
brentbas_block
enddo_line
(b)
do_line
brentbas_block
break_continue_line
brentbas_block
enddo_line
normal_line:
(1) basic_line
(2) blank_line
(3) call_line
(a) {basic_line :} name{(expresion_list)}]
(b) {basic_line :} IF logical_expression name{(expresion_list)}]
(4) goto_line
(a) {basic_line :} GOTO(name)]
(b) {basic_line :} IF logical_expression GOTO(name)]
(5) include_line
INCLUDE "file_spec"]
(6) label_line
LABEL name
(7) resume_line
(a) {basic_line :} RESUME(name)]
(b) {basic_line :} IF logical_expression RESUME(name)]
Copyright 1985 By Brent D. Weaver Page 17
The Brentbas User's Manual
then_line:
(1) {basic_line:} IF logical_expression then BEGIN]
(2) {basic_line:} IF logical_expression THEN]
break_continue_line:
(1) {basic_line:} BREAK]
(2) {basic_line:} IF logical_expression BREAK]
(3) {basic_line:} CONTINUE]
(4) {basic_line:} IF logical_expression CONTINUE]
cend_line:
CEND]
ENDCASE]
do_line:
(1) {basic_line:} FOR variable=expression TO expression DO]
(2) {basic_line:} WHILE logical_expression DO]
else_line:
{basic_line :} ELSE]
enddo_line:
{basic_line :} DOEND]
{basic_line :} ENDDO]
ifend_line:
(1) {basic_line :} ENDIF]
(2) {basic_line :} IFEND]
initial_line:
INITIAL]
initend_line:
INITEND]
case_line:
{basic_line:} CASE expression OF]
otherwise_line:
OTHERWISE]
pend_line:
PEND]
procedure_line:
PROCEDURE name{(variable_list)}]
program_line:
PROGRAM]
Copyright 1985 By Brent D. Weaver Page 18
The Brentbas User's Manual
selection_line:
expression_list :]
expresion_list:
(1) see BASIC manual
(2) expression{, expression_list}
basic_line:
basic_statement {: basic_line}
basic_statement:
See BASIC manual
name:
string of characters not including " , : ] ( ) '
Copyright 1985 By Brent D. Weaver Page 19
The Brentbas User's Manual
14. Error Messages
"Missing PEND]"
Each PROCEDURE statement must be followed by a PEND]
statement before another PROCEDURE or INITIAL statement
is found.
"... not in procedure list"
The procedure must be declared before being called.
"arguments do not match "
The call of a procedure must have the same number of
arguments as were declared in the PROCEDURE statement.
"Out of Memory"
Too many of the following statements were used: proce-
dure, label, goto, break, continue, case.
"label ... in ... was not found"
A goto statement could not be matched to a LABEL state-
ment.
"Unmatched ELSE]"
An ELSE statement could not be matched to a IF..THEN
statement.
"Unmatched IFEND]"
An ELSE statement could not be matched to a IF..THEN
statement.
"DO statement must begin with FOR or WHILE".
"Unmatched ENDDO]".
The ENDDO statement could not be matched to a DO state-
ment.
"Extra PEND]"A PEND statement could not be matched to a PROCEDURE
statement.
Copyright 1985 By Brent D. Weaver Page 20
The Brentbas User's Manual
"Unmatched statements in Procedure"
The procedure was missing a IFEND, CEND, or ENDDO state-
ment.
"BREAK statement without matching ENDDO"
A BREAK statement was found outside a DO...ENDO loop.
"CONTINUE statement without matching ENDDO"
A CONTINUE statement was found outside a DO...ENDO loop.
"Statement should be CASE...OF] "
An OF statement did not start with the word "CASE".
"SELECTION line without preceding CASE...OF"
"Missing Expression in Case Selection "
"Unmatched IF] or CASE...OF] in SELECTION"
A IFEND or CEND statement was missing within a selection.
"Unmatched IF] or CASE] in CASE...OF ...CEND] construction"
A IFEND or CEND statement was missing within a "other-
wise" section.
"Unmatched CEND] statement"
A CEND statement could not be matched with a CASE..OF
statement.
"Includes nested too deep"
"... open error"
An include file could not be opened. Usually file not
found error.
Copyright 1985 By Brent D. Weaver Page 21